package semana3.strings.ejercicios.ej17_contarChar;

import java.util.Scanner;

public class ContarChar {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		System.out.println("Introduce una frase: ");
		String frase = scan.nextLine();
		System.out.println("Introduce un caracter: ");
		String primerCaracter = scan.next();

		char caracter = primerCaracter.charAt(0);
		int solucion = numeroCaracterCadena(frase, caracter);
		System.out.println("El numero de '" + primerCaracter
				+ "' en la frase es :" + solucion);

	}

	private static int numeroCaracterCadena(String cadena, char c) {
		int contador = 0;
		for (int i = 0; i < cadena.length(); i++) {
			if (cadena.charAt(i) == c) {
				contador++;
			}
		}

		return contador;
	}

}
